package com.jiangnan.view;

import com.jiangnan.constants.ThemeStyle;
import com.jiangnan.context.GlobalContext;

import javax.swing.*;
import java.awt.*;

/**
 * 主框架，单例模式
 * @author chenliang
 * @email wschenliang@aliyun.com
 */
public class HomeFrame extends BaseFrame {

    private static HomeFrame homeFrame;

    private HomeFrame() throws HeadlessException {
        //设置图标
        this.setIconImage(new ImageIcon(getClass().getResource("/image/wireshark.png")).getImage());
        this.setTitle("SimpleSniffer");
        this.setSize(1200,1000);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //homeJPanel
        HomeJPanel homePanel = new HomeJPanel(this);
        //homeJMenuBar
        HomeJMenuBar homeJMenuBar = new HomeJMenuBar(this);

        this.setContentPane(homePanel);
        this.setJMenuBar(homeJMenuBar);
    }

    public static HomeFrame frame() {
        if (homeFrame == null) {
            homeFrame = new HomeFrame();
        }
        //注入全局变量
        GlobalContext.homeFrame(homeFrame);
        return homeFrame;
    }

    public static void main(String[] args) {
        //设置主题
        try {
            UIManager.setLookAndFeel(ThemeStyle.defaultStyle);
        } catch (Exception e) {
            e.printStackTrace();
        }
        HomeFrame.frame().setVisible(true);
    }
}
